package com.open.capacity.finance.task;


import com.open.capacity.finance.entity.SpringScheduledCron;
import com.open.capacity.finance.service.SpringScheduledCronService;
import com.open.capacity.utils.SpringUtil;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * @author yudong
 * @date 2019/5/11
 */
public interface ScheduledOfTask extends Runnable {


    void setCronId(Integer cronId);

    /**
     * 定时任务方法
     */
    void execute() throws UnsupportedEncodingException;

    void trigger(String startTime) throws IOException;

    /**
     * 实现控制定时任务启用或禁用的功能
     */
    @Override
    default void run() {
//        SpringScheduledCronService repository = SpringUtil.getBean(SpringScheduledCronService.class);
//        SpringScheduledCron scheduledCron = repository.findByKey(this.getClass().getName());
//        if (1 != scheduledCron.getStatus()) {
//            return;
//        }
        try {
            execute();
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}
